package Exercise;

import java.util.HashMap;
import java.util.HashSet;

/**
 * 输出数组中第一个只出现一次的数字
 */
public class demo3 {
    public static int singleNumber(int []nums){
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if(!set.contains(nums[i])){
                set.add(nums[i]);
            }else{
                set.remove(nums[i]);
            }
        }

        for (int i = 0; i < nums.length; i++) {
            if(set.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int [] array = {1,2,2,3,3};
        int ret = singleNumber(array);
        System.out.println(ret);
    }
}
